<template>
  <div class="app-container">
    <div class="Search">
      <!--工具条-->
      <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
        <el-form :inline="true" :model="query">
          <el-form-item v-has="'PLATFROM_TENANT_QUERY'">
            <el-cascader ref="tenantTree" placeholder="所属租户" :props="tenantProps" :options="tenantOptions" @change="selectTenant" clearable collapse-tags filterable></el-cascader>
          </el-form-item>
          <el-form-item>
            <el-cascader ref="organTree" placeholder="所属组织" :props="props" :options="organOptions" @change="selectOrgan" collapse-tags clearable filterable></el-cascader>
          </el-form-item>
          <el-form-item>
            <el-input v-model="query.params.realName" placeholder="姓名" />
          </el-form-item>
          <el-form-item>
            <el-input v-model="query.params.email" placeholder="电子邮件" />
          </el-form-item>
          <el-form-item>
            <el-input v-model="query.params.telephone" placeholder="联系电话" />
          </el-form-item>
          <el-form-item>
            <el-input v-model="query.params.address" placeholder="住址" />
          </el-form-item>
          <el-form-item>
            <el-select v-model="query.params.enable" placeholder="是否生效">
              <el-option v-for="item in query.enableOptions" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="fetchData">查询</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="success" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </div>
    <div class="block">
      <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row>
        <el-table-column align="center" label="序号" width="45">
          <template slot-scope="scope">
            {{ scope.$index }}
          </template>
        </el-table-column>
        <el-table-column label="所属商铺" width="110">
          <template slot-scope="scope">
            {{ scope.row.storeName }}
          </template>
        </el-table-column>
        <el-table-column label="所属用户" width="110">
          <template slot-scope="scope">
            {{ scope.row.userName }}
          </template>
        </el-table-column>
        <el-table-column label="姓名" width="110">
          <template slot-scope="scope">
            {{ scope.row.realName }}
          </template>
        </el-table-column>
        <el-table-column label="电子邮件" width="110">
          <template slot-scope="scope">
            {{ scope.row.email }}
          </template>
        </el-table-column>
        <el-table-column label="联系电话" width="110">
          <template slot-scope="scope">
            {{ scope.row.telephone }}
          </template>
        </el-table-column>
        <el-table-column label="住址" width="110">
          <template slot-scope="scope">
            {{ scope.row.address }}
          </template>
        </el-table-column>
        <el-table-column label="是否生效" width="110">
          <template slot-scope="scope">
            {{ scope.row.enable }}
          </template>
        </el-table-column>
        <!-- <el-table-column label="创建者" width="110">
                <template slot-scope="scope">
                {{ scope.row.createBy }}
                </template>
                </el-table-column>
                <el-table-column label="建创者" width="110">
                <template slot-scope="scope">
                {{ scope.row.createDate }}
                </template>
                </el-table-column>
                <el-table-column label="更新者" width="110">
                <template slot-scope="scope">
                {{ scope.row.updateBy }}
                </template>
                </el-table-column>
                <el-table-column label="更新日期" width="110">
                <template slot-scope="scope">
                {{ scope.row.updateDate }}
                </template>
                </el-table-column>
                <el-table-column label="备注" width="110">
                <template slot-scope="scope">
                {{ scope.row.remark }}
                </template>
                </el-table-column>
                <el-table-column label="删除标识" width="110">
                <template slot-scope="scope">
                {{ scope.row.idDeleted }}
                </template>
                </el-table-column> -->
        <el-table-column align="center" prop="created_at" label="操作" width="200">
          <template slot-scope="scope">
            <el-button type="warning" icon="el-icon-edit" size="mini" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="block">
      <el-pagination :current-page="currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </div>
    <div class="block">
      <!--弹框-->
      <el-dialog :title="titleMap[dialogStatus]" :visible.sync="dialogFormVisible">
        <el-form :model="form" :rules="EmployeeRules" ref="EmployeeForm">
          <el-form-item v-if="addForVisible" label="编号" prop="id">
            <el-input v-model="form.id" placeholder="编号" auto-complete="off" />
          </el-form-item>
          <el-form-item label="所属商铺" hidden required prop="storeId">
            <el-input v-model="form.storeId" placeholder="所属用户" auto-complete="off" />
          </el-form-item>
          <el-form-item label="所属商铺" required prop="storeId">
            <el-input v-model="form.storeName" placeholder="所属商铺" @focus="showStoreDatas" suffix-icon="el-icon-s-shop" auto-complete="off" />
          </el-form-item>
          <el-form-item label="关联用户" hidden required prop="userId">
            <el-input v-model="form.userId" placeholder="关联用户" auto-complete="off" />
          </el-form-item>
          <el-form-item label="关联用户" required prop="userId">
            <el-input v-model="form.userName" placeholder="关联用户" @focus="showUserDatas" suffix-icon="el-icon-user" auto-complete="off" />
          </el-form-item>
          <el-form-item label="姓名" required prop="realName">
            <el-input v-model="form.realName" placeholder="姓名" auto-complete="off" />
          </el-form-item>
          <el-form-item label="电子邮件" required prop="email">
            <el-input v-model="form.email" placeholder="电子邮件" auto-complete="off" />
          </el-form-item>
          <el-form-item label="联系电话" required prop="telephone">
            <el-input v-model="form.telephone" placeholder="联系电话" auto-complete="off" />
          </el-form-item>
          <el-form-item label="住址" required prop="address">
            <el-input v-model="form.address" placeholder="住址" auto-complete="off" />
          </el-form-item>
          <el-form-item label="是否生效" required prop="enable">
            <el-select v-model="form.enable" placeholder="是否生效">
              <el-option v-for="item in query.options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <!-- <el-form-item label="创建者"  required prop="createBy">
                        <el-input v-model="form.createBy" placeholder="创建者"  auto-complete="off"/>
                    </el-form-item>
                                <el-form-item label="建创者"  required prop="createDate">
                        <el-date-picker v-model="form.createDate" type="date" placeholder="建创者">
                        </el-date-picker>
                    </el-form-item>
                                                <el-form-item label="更新者"  required prop="updateBy">
                        <el-input v-model="form.updateBy" placeholder="更新者"  auto-complete="off"/>
                    </el-form-item>
                                <el-form-item label="更新日期"  required prop="updateDate">
                        <el-date-picker v-model="form.updateDate" type="date" placeholder="更新日期">
                        </el-date-picker>
                    </el-form-item>
                                    <el-form-item label="备注" required prop="remark">
                        <el-input v-model="form.remark" placeholder="备注"  auto-complete="off"/>
                    </el-form-item> -->
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="handleEditSave">确 定</el-button>
        </div>
      </el-dialog>
    </div>
    <div>
      <el-dialog :title="titleMap[dialogStatus]" width="50%" :visible.sync="dialogSelectUserFormVisible">
        <el-table v-loading="listLoading" :data="userList" ref="selectedUserTable" element-loading-text="Loading" @selection-change="handleSelectedUser" border fit highlight-current-row>
          <el-table-column type="selection" width="55">
          </el-table-column>
          <el-table-column align="center" label="序号" width="95">
            <template slot-scope="scope">
              {{ scope.$index }}
            </template>
          </el-table-column>
          <el-table-column label="用户名" width="110">
            <template slot-scope="scope">
              {{ scope.row.userName }}
            </template>
          </el-table-column>
          <el-table-column label="所属机构">
            <template slot-scope="scope">
              {{ scope.row.organName }}
            </template>
          </el-table-column>
        </el-table>
        <el-pagination :current-page="query.page.user.currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="query.page.user.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="query.page.user.total" @size-change="handleUserSizeChange" @current-change="handleUserCurrentChange" >
        </el-pagination>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogSelectUserFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="handleGetSelectedUser">确 定</el-button>
        </div>
      </el-dialog>
    </div>
    <div>
      <el-dialog :title="titleMap[dialogStatus]" width="50%" :visible.sync="dialogSelectStoreFormVisible">
        <el-table v-loading="listLoading" :data="storeList" ref="selectedStoreTable" element-loading-text="Loading" @selection-change="handleSelectedStore" border fit highlight-current-row>
          <el-table-column type="selection" width="55">
          </el-table-column>
          <el-table-column align="center" label="序号" width="95">
            <template slot-scope="scope">
              {{ scope.$index }}
            </template>
          </el-table-column>
          <el-table-column label="店铺名称" width="110">
            <template slot-scope="scope">
              {{ scope.row.storeName }}
            </template>
          </el-table-column>
          <el-table-column label="所属组织">
            <template slot-scope="scope">
              {{ scope.row.organId }}
            </template>
          </el-table-column>
        </el-table>
        <el-pagination :current-page="query.page.user.currentPage" :page-sizes="[10, 20, 30, 40]" :page-size="query.page.user.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="query.page.user.total" @size-change="handleUserSizeChange" @current-change="handleUserCurrentChange" >
        </el-pagination>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogSelectStoreFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="handleGetSelectedStore">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import { getList, doDelete, doEdit } from '@/api/employee/'
import { getList as queryUsers } from '@/api/User/'
import { getList as queryStores } from '@/api/Store/'
import { getTenantId, getOrganId, getOrganPath, handleBuildTreeDataStruct, getSelectedNodes, getSelectedNodesObject, getCurrentLoginUserId } from '@/api/utils'
import { getList as getOrganPager, querySubordinateOrgan, queryAssigneeOrgan } from '@/api/Organ'
import { getTenantList, getOrganList, getDictionary } from '@/utils/auth'
import localStorageUtil from '@/utils/localStorageUtil'



export default {
  data() {
    return {
      list: null,
      listLoading: true,
      total: 5,
      currentPage: 1,
      pageSize: 10,
      dialogFormVisible: false,
      addForVisible: false,
      dialogSelectUserFormVisible: false,
      dialogSelectStoreFormVisible: false,
      userList: null,
      storeList: null,
      selectedUser: null,
      selectedStore: null,
      organTree: [],
      form: {
        id: '',
        tenantId: '',
        organId: '',
        userId: '',
        userName: '',
        storeId: '',
        storeName: '',
        realName: '',
        email: '',
        telephone: '',
        address: '',
        enable: '',
        createBy: '',
        createDate: '',
        updateBy: '',
        updateDate: '',
        remark: '',
        idDeleted: ''
      },
      // 新增or编辑弹框标题(根据点击的新增or编辑按钮显示不同的标题)
      titleMap: {
        add: '新增',
        edit: '编辑'
      },
      EmployeeRules: {},
      props: { // 配置项（必选）
        value: 'id',
        label: 'organName',
        children: 'children',
        title: '组织',
        multiple: false,
        checkStrictly: true,
        emitPath: false
        // disabled:true
      },
      organTreeProps: {
        children: 'children',
        label: 'organName',
        url: 'url'
      },
      tenantProps: { // 配置项（必选）
        value: 'id',
        label: 'organName',
        children: 'children',
        title: '租户',
        multiple: false,
        checkStrictly: true,
        emitPath: false
        // disabled:true
      },
      organFormOptions: [],
      tenantOptions: [],
      organOptions: [{ id: '1', parentId: '2', organName: '平台', children: [] }],
      // 新增和编辑弹框标题
      dialogStatus: '',
      query: {
        params: {
          id: '', //编号,
          tenantId: getTenantId(), //,
          organId: '', //,
          userId: '', //所属用户,
          realName: '', //姓名,
          email: '', //电子邮件,
          telephone: '', //联系电话,
          address: '', //住址,
          enable: '', //是否生效,
          createBy: '', //创建者,
          createDate: '', //建创者,
          updateBy: '', //更新者,
          updateDate: '', //更新日期,
          remark: '', //备注,
          idDeleted: '', //删除标识,

        },
        user: {
          id: '',
          enable: '1',
          tenantId: '',
          isAccountNonExpired: '0',
          isLock: '0',
          isSuperMgr: '0',
          organId: '',
          organPath: '',
          password: '',
          remark: '',
          updateBy: '',
          updateDate: '',
          userName: ''
        },
        store: {
          addressId: '',
          createBy: '',
          createDate: '',
          enable: '',
          id: '',
          latitude: '',
          longitude: '',
          organId: '',
          organPath: '',
          remark: '',
          storeName: '',
          updateBy: '',
          updateDate: ''
        },
        page: {
          user: {
            total: 5,
            currentPage: 1,
            pageSize: 10
          },
          store: {
            total: 5,
            currentPage: 1,
            pageSize: 10
          }
        },
        timeValue: '',
        enableOptions: [{
          value: '0',
          label: '失效'
        }, {
          value: '1',
          label: '生效'
        }],
        value: ''
      }
    }
  },
  created() {
    this.initOrganTree(() => {
      this.setOrganQueryType()
    }, getOrganPath())
    this.initOrganFormTree()
    this.handleFiltTenant()
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      this.createOrganQuery()
      getList(this.query.params, this.currentPage, this.pageSize).then(response => {
        const data = response.data
        if (!data.entities || typeof data.successful != 'undefined') {
          this.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }
        this.total = data.totalCount
        this.pageSize = data.pageSize
        this.currentPage = data.currentPage
        this.list = data.entities
        this.listLoading = false
      })
    },
    createOrganQuery() {
      // 选中了租户
      let tenantSelected = this.$refs['tenantTree'] && this.$refs['tenantTree'].getCheckedNodes() || []
      let organSelected = this.$refs['organTree'] && this.$refs['organTree'].getCheckedNodes() || []
      let that = this
      if (tenantSelected.length) {
        this.query.params.tenantId = tenantSelected[0].data.id
        if (organSelected.length) {
          if (this.props.multiple) {
            this.query.params.organId = null
            this.query.params.organIds = []
            if (organSelected.length) {
              organSelected.forEach(function(element) {
                that.query.params.organIds.push(element.data.id)
              })
            }
          } else if (organSelected.length) {
            this.query.params.organPath = organSelected[0].data.organPath
          }

        } else {
          this.query.params.organId = getOrganId()
        }
      } else {
        this.query.params.tenantId = getTenantId()
        if (organSelected.length) {
          if (this.props.multiple) {
            this.query.params.organId = null
            this.query.params.organIds = []
            if (organSelected.length) {
              organSelected.forEach(function(element) {
                that.query.params.organIds.push(element.data.id)
              })
            }
          } else if (organSelected.length) {
            this.query.params.organPath = organSelected[0].data.organPath
          }
        } else {
          this.query.params.organId = getOrganId()
        }
      }
    },
    initOrganTree(fn, filter, that) {
      this.listLoading = true
      let data = getOrganList()
      if (filter) {
        data = data.filter(function(item, index) {
          return item.organPath.indexOf(filter) >= 0
        })
      }
      if (that && that.organFormOptions && that.organFormOptions.length >= 0) {
        that.organFormOptions = handleBuildTreeDataStruct(data, 'id', 'parentId')
      } else {
        this.organOptions = handleBuildTreeDataStruct(data, 'id', 'parentId')
      }
      this.listLoading = false
      if (fn) {
        fn()
      }
    },
    initOrganFormTree(fn, filter) {
      this.initOrganTree(fn, filter, this)
    },
    setOrganQueryType() {
      this.organQueryModelChange(localStorageUtil.fetch("SYSTEM_SETTING_ORGAN_QUERY_MODEL"))
    },
    selectOrgan(nodes) {
      let nodesInfo = this.$refs['organTree'].getCheckedNodes()
      let that = this
      this.query.params.organPath = ''
      this.query.params.organIds = []
      if (this.props.multiple) {
        this.query.params.organIds = []
        if (nodesInfo.length) {
          nodesInfo.forEach(function(element) {
            that.query.params.organIds.push(element.data.id)
          })
        }
      } else if (nodesInfo.length) {
        this.query.params.organPath = nodesInfo[0].data.organPath
      }
    },
    selectTenant(nodes) {
      debugger
      let nodesInfo = this.$refs['tenantTree'].getCheckedNodes()
      let that = this
      this.query.params.tenantId = ''
      this.query.params.tenantIds = []
      this.query.params.organId = null
      this.query.params.organIds = []
      this.query.params.organPath = null

      if (this.tenantProps.multiple) {
        this.query.params.tenantIds = []
        if (nodesInfo.length) {
          nodesInfo.forEach(function(element) {
            that.query.params.tenantIds.push(element.data.id)
          })
        }
      } else if (nodesInfo.length) {
        this.query.params.tenantId = nodesInfo[0].data.id
        this.initOrganTree(function() {
          that.setOrganQueryType()
        }, nodesInfo[0].data.organPath)
      } else {
        this.initOrganTree(function() {
          that.setOrganQueryType()
        })
      }
    },
    chooseTenantForm(nodes) {
      let nodesInfo = this.$refs['tenantTreeForm'].getCheckedNodes()
      this.form.tenantId = null
      let that = this
      debugger
      if (nodesInfo.length) {
        this.form.tenantId = nodesInfo[0].data.id
        this.initOrganFormTree(function() {
          that.setOrganQueryType()
        }, nodesInfo[0].data.organPath, this.organFormOptions)
      } else {
        this.initOrganFormTree(function() {
          that.setOrganQueryType()
        }, null, this.organFormOptions)
      }
    },
    organQueryModelChange(organQueryModel) {
      if (organQueryModel == 'selected') {
        this.props.multiple = true
      } else if (organQueryModel == 'selfAndSub') {
        this.props.multiple = false
      }
    },
    chooseOrganForm(nodes) {
      let nodesInfo = this.$refs['organTreeForm'].getCheckedNodes()
      if (nodesInfo[0]) {
        this.form.organPath = nodesInfo[0].data.organPath
        this.form.organId = nodesInfo[0].data.id
        this.form.tenantId = nodesInfo[0].data.tenantId
      }
    },
    handleFiltTenant() {
      let data = getOrganList()
      this.tenantOptions = data.filter(function(item, index) {
        return item.type == 0 || item.type == 1;
      })
    },
    handleSizeChange(val) {
      this.currentPage = 1
      this.pageSize = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.fetchData()
    },
    // 新增
    handleAdd() {
      // 显示弹框
      this.dialogFormVisible = true
      // 新增弹框标题
      this.dialogStatus = 'add'

      this.form.id = ''
      this.form.tenantId = getTenantId()
      this.form.organId = getOrganId()
      this.form.organPath = getOrganPath()
      this.form.userId = ''
      this.form.storeId = ''
      this.form.storeName = ''
      this.form.userName = ''
      this.form.realName = ''
      this.form.email = ''
      this.form.telephone = ''
      this.form.address = ''
      this.form.enable = ''
      this.form.createBy = ''
      this.form.createDate = ''
      this.form.updateBy = ''
      this.form.updateDate = ''
      this.form.remark = ''
      this.form.idDeleted = ''
      this.addForVisible = false
    },
    // 编辑
    handleEdit(index, row) {
      console.log(index)
      console.log(row)
      this.form.id = row.id
      this.form.tenantId = row.tenantId
      this.form.organId = row.organId
      this.form.storeId = row.storeId
      this.form.storeName = row.storeName
      this.form.userId = row.userId
      this.form.userName = row.userName
      this.form.realName = row.realName
      this.form.email = row.email
      this.form.telephone = row.telephone
      this.form.address = row.address
      this.form.enable = row.enable
      this.form.createBy = row.createBy
      this.form.createDate = row.createDate
      this.form.updateBy = row.updateBy
      this.form.updateDate = row.updateDate
      this.form.remark = row.remark
      this.form.idDeleted = row.idDeleted
      this.addForVisible = true
      // 显示弹框
      this.dialogFormVisible = true
      // 编辑弹框标题
      this.dialogStatus = 'edit'
    },
    handleDelete(index, row) {
      console.log(index)
      console.log(row)

      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        doDelete(row.id).then(response => {
          const gateway = response.data
          let data = gateway.data
          if (data.successful) {
            this.$message({
              type: 'success',
              message: '操作成功!'
            })
            this.fetchData();
          } else {
            this.$message({
              type: 'info',
              message: data.description || getSystemErrorCode(data.status)
            })
          }

        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    handleEditSave() {
      debugger

      doEdit(this.form).then(response => {
        const gateway = response.data
        let data = gateway.data
        if (data.successful) {
          this.$message({
            type: 'success',
            message: '操作成功!'
          })
          this.fetchData();
        } else {
          this.$message({
            type: 'info',
            message: data.description || getSystemErrorCode(data.status)
          })
        }
      })
      this.listLoading = false
      this.dialogFormVisible = false
    }
},
handleReset() {
    this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
      center: true
    }).then(() => {
      this.$message({
        type: 'success',
        message: '删除成功!'
      })
    }).catch(() => {
      this.$message({
        type: 'info',
        message: '已取消删除'
      })
    })
  },
  showUserDatas() {
    this.dialogSelectUserFormVisible = true
    this.listLoading = false
    this.query.user.organId = getOrganId()
    this.query.user.isSuperMgr = null
    queryUsers(this.query.user,
      this.query.page.user.currentPage,
      this.query.page.user.pageSize).then(response => {
      const gateway = response.data
      let data = gateway.data
      if (data.successful) {
        this.$message({
          type: 'success',
          message: '操作成功!'
        })
        this.query.page.user.total = data.totalCount
        this.query.page.user.pageSize = data.pageSize
        this.query.page.user.currentPage = data.currentPage
        this.userList = data.entities
        this.listLoading = false
      } else {
        this.$message({
          type: 'info',
          message: data.description || getSystemErrorCode(data.status)
        })
      }
    })
  },
  handleUserSizeChange(val) {
    this.query.page.user.currentPage = 1
    this.query.page.user.pageSize = val
    this.showUserDatas()
  },
  handleUserCurrentChange(val) {
    this.query.page.user.currentPage = val
    this.showUserDatas()
  },
  showStoreDatas() {
    this.dialogSelectStoreFormVisible = true
    this.listLoading = false
    queryStores(this.query.store,
      this.query.page.store.currentPage,
      this.query.page.store.pageSize).then(response => {
      let data = response.data
      this.query.page.store.total = data.totalCount
      this.query.page.store.pageSize = data.pageSize
      this.query.page.store.currentPage = data.currentPage
      this.storeList = data.entities
      this.listLoading = false
    })
  },
  handleStoreSizeChange(val) {
    this.query.page.store.currentPage = 1
    this.query.page.store.pageSize = val
    this.showStoreDatas()
  },
  handleStoreCurrentChange(val) {
    this.query.page.store.currentPage = val
    this.showStoreDatas()
  },
  selectOrgan(nodes) {
    let nodesInfo = this.$refs['organTree'].getCheckedNodes()
    // this.query.params.organPath = nodesInfo[0].data.organPath
    console.log(nodesInfo)
    this.query.params.organId = nodesInfo[0].data.id

  },
  queryUsersOfTenant() {

  },
  handleSelectedUser(selectedUsers) {
    this.selectedUser = selectedUsers[0]
    if (selectedUsers.length > 1) {
      this.$refs.selectedUserTable.clearSelection();
      this.$refs.selectedUserTable.toggleRowSelection(selectedUsers.pop())
    }
  },
  handleGetSelectedUser() {
    if (!this.selectedUser) {
      this.$message({
        type: 'warning',
        message: '请选择需要绑定的用户!'
      })
      return;
    }
    this.$confirm('确定绑定所选的用户吗?', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
      center: true
    }).then(() => {
      this.form.userId = this.selectedUser.id
      this.form.userName = this.selectedUser.userName
      this.dialogSelectUserFormVisible = false
    }).catch(() => {
      this.$message({
        type: 'info',
        message: '操作已取消！'
      })
    })
  },
  handleSelectedStore(selectedStores) {
    this.selectedStore = selectedStores[0]
    if (selectedStores.length > 1) {
      this.$refs.selectedStoreTable.clearSelection();
      this.$refs.selectedStoreTable.toggleRowSelection(selectedStores.pop())
    }
  },
  handleGetSelectedStore() {
    if (!this.selectedStore) {
      this.$message({
        type: 'warning',
        message: '请选择铺商!'
      })
      return;
    }
    this.$confirm('确定所选的铺商吗?', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
      center: true
    }).then(() => {
      this.form.storeId = this.selectedStore.id
      this.form.storeName = this.selectedStore.storeName
      this.dialogSelectStoreFormVisible = false
    }).catch(() => {
      this.$message({
        type: 'info',
        message: '操作已取消！'
      })
    })
  },
}


</script>
